package com.shanghaionstar.discover.geofence.service;

import android.content.Context;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.onstar.cn.api.UsersService;
import com.onstar.cn.common.util.Constants;
import com.onstar.cn.framework.annotation.http.HeadsValue;
import com.onstar.cn.framework.annotation.http.Request;
import com.onstar.cn.framework.mvp.base.core.BaseService;
import com.onstar.cn.framework.network.HttpInjectUtils;
import com.onstar.cn.framework.network.entity.RequestEntity;
import com.onstar.cn.framework.network.enumtype.HttpAccept;
import com.onstar.cn.framework.network.enumtype.HttpMethod;
import com.onstar.cn.framework.network.enumtype.Language;
import com.onstar.cn.mag.poi.FavoriteEntity;
import com.shanghaionstar.utils.ApplicationUtil;
import com.shanghaionstar.utils.BusinessUtil;
import com.shanghaionstar.utils.NetConnectUtil;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by 7828wc on 16/7/21.
 */
public class GeofenceCenterService extends BaseService<List<FavoriteEntity>> {
    private Context context;

    public GeofenceCenterService(Context context) {
        this.context = context;
    }

    @Override
    @Request(heads = @HeadsValue(accept = HttpAccept.JSON, language = Language.AUTO), method = HttpMethod.GET)
    public RequestEntity getRequestEntity() {
        UsersService service = new UsersService(Constants.CURRENT_SERVER_URL);
        RequestEntity entity = NetConnectUtil.getAuthRequestEntity(context);
        entity = service.getFavoriteDestinationList(entity, ApplicationUtil.getInstance().getIdpID());
        entity = HttpInjectUtils.injectHttp(getClass(), "getRequestEntity", entity);
        return entity;
    }

    @Override
    public List<FavoriteEntity> jsonToBean(String json) {
        return new Gson().fromJson(json,new TypeToken<ArrayList<FavoriteEntity>>(){}.getType());
    }





}
